package com.bw.my.mvvm.user.viewmodel;

import androidx.databinding.ObservableField;


import com.bw.mvvm.entity.BaseEntity;
import com.bw.mvvm.mvvm.viewmodel.BaseViewModel;
import com.bw.mvvm.utils.SpUtils;
import com.bw.my.mvvm.model.entity.UserEntity;
import com.bw.my.mvvm.model.entity.usergreendao.UserDaoEntity;
import com.bw.my.mvvm.user.model.LoginModel;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.greendao.query.WhereCondition;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

public class LoginViewModel extends BaseViewModel<LoginModel>{

    public ObservableField<String> phone = new ObservableField<>();
    public ObservableField<String> lock = new ObservableField<>();
    public String pushId ="1";
    @Override
    protected void result(BaseEntity entity) {
        if (entity.getMessage().equals("登录成功")){
            EventBus.getDefault().post("登录成功");
            String s = phone.get();
            SpUtils.setUser(s);
            SpUtils.setId("453");
        }
    }

    public void back(){
        finishPage();
    }


    public void loginClick(){

        HashMap<String,Object> map = new HashMap<>();
        map.put("mobile",phone.get());
        map.put("pushId",pushId);
        map.put("pwd",lock.get());
        RequestBody body = m.createBody(map);
        m.requestLogin(body).subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(this);
    }

}
